package com.ziyun.erp.web.modules.goodsCategoryScholarship.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.plugins.Page;
import com.utility.New;
import com.utility.StringUtils;
import com.ziyun.erp.common.utils.UserUtils;
import com.ziyun.erp.modules.goods.entity.GoodsAttributeEntity;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.goodsCategoryScholarship.entity.GoodsCategoryScholarshipEntity;
import com.ziyun.erp.modules.goodsCategoryScholarship.service.GoodsCategoryScholarshipService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 奖励金支付比例和分类关系表
 *
 * @author xueqz
 * @email 
 * @date 2018-11-30 09:43:36
 */
@RestController
@RequestMapping("goodsCategoryScholarship/goodscategoryscholarship")
public class GoodsCategoryScholarshipController {
    @Autowired
    private GoodsCategoryScholarshipService goodsCategoryScholarshipService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("goodsCategoryScholarship:goodscategoryscholarship:list")
    public R list(Page<GoodsCategoryScholarshipEntity> page,@RequestParam Map<String, Object> params){
//        PageUtils page = goodsCategoryScholarshipService.queryPage(params);
        page.setSize(Integer.parseInt((String) params.get("limit")));
        page.setCurrent(Integer.parseInt((String) params.get("page")));
        Page<GoodsCategoryScholarshipEntity> resultPage = goodsCategoryScholarshipService.queryNewPage(page, params);
        return R.ok().put("page", resultPage);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("goodsCategoryScholarship:goodscategoryscholarship:info")
    public R info(@PathVariable("id") Integer id){
        GoodsCategoryScholarshipEntity goodsCategoryScholarship = goodsCategoryScholarshipService.selectById(id);

        return R.ok().put("goodsCategoryScholarship", goodsCategoryScholarship);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("goodsCategoryScholarship:goodscategoryscholarship:save")
    public R save(@RequestBody GoodsCategoryScholarshipEntity goodsCategoryScholarship){
        goodsCategoryScholarship.setCreateName(UserUtils.getCurentUser().getUsername());
        goodsCategoryScholarshipService.insert(goodsCategoryScholarship);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("goodsCategoryScholarship:goodscategoryscholarship:update")
    public R update(@RequestBody GoodsCategoryScholarshipEntity goodsCategoryScholarship){
        ValidatorUtils.validateEntity(goodsCategoryScholarship);
        goodsCategoryScholarshipService.updateAllColumnById(goodsCategoryScholarship);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("goodsCategoryScholarship:goodscategoryscholarship:delete")
    public R delete(@RequestBody Integer[] ids){
//        goodsCategoryScholarshipService.deleteBatchIds(Arrays.asList(ids));
        goodsCategoryScholarshipService.flagDel(StringUtils.join(ids,","));

        return R.ok();
    }

    /**
     * getScholarShipByCatId
      */
    @RequestMapping("/getScholarShipByCatId/{catId}")
    public R getScholarShipByCatId(@PathVariable("catId") Integer catId){

        return goodsCategoryScholarshipService.getScholarShipByCatId(catId);
    }
}
